package com.atguigu.springcloud.controller;


import com.atguigu.springcloud.service.PaymentHystrixService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
//@DefaultProperties(defaultFallback = "error")
public class OrderHystirxController {
    @Autowired
    private PaymentHystrixService paymentHystrixService;


    @GetMapping("/consumer/payment/hystrix/ok/{id}")
//    @HystrixCommand
    public String OK(@PathVariable("id")Integer id){
//      int i=9/0;
      return paymentHystrixService.OK(id);
    }
    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
//    @HystrixCommand(fallbackMethod = "TimeOutHandler",commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",
//                    value = "1000")//设定最大超时时间为1s,超过了就出错
//    })//如果本方法出事了，TimeOutHandler方法来兜底
//    @HystrixCommand
    public String TimeOut(@PathVariable("id")Integer id){
//        int i=9/0;
        return paymentHystrixService.TimeOut(id);
    }
//    public String TimeOutHandler(@PathVariable("id")Integer id){
//        return "消费者提醒您超时或运行错误";
//    }
    //全局fallback方法
//    public String error(){
//        return "error了";
//    }
}
